
// Open MoneySpinner Suite v1
// An open source business management software system written in Java and MySQL
// Recommended IDE is NetBeans IDE 7.0.1
// Support Web Site: http://www.milliscript.com
//
// Copyright (C) 2014, Abiodun Aremu, Ibadan/NIGERIA.
// Open MoneySpinner Suite is distributed under the terms of the Apache License version 2.0
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package openmoneyspinnersuite;

/**
 *
 * @author Abiodun Aremu
 */

import javax.swing.*;
public class ViewProfileMembers extends javax.swing.JInternalFrame {

    Object[][] tableObject=new Object[][]{};
    Systems systems=new Systems();
    Thread processThread=new Thread();
    Thread titleThread=new Thread();
    int numOfColumn=1;
    String profileName="",query="Member",tbAttribute[],dbMemberRecord[][],multiRow,profileCode;
    /** Creates new form ViewCredit */
    public ViewProfileMembers() {
        initComponents();

        jTable1.setModel(new javax.swing.table.DefaultTableModel(
            tableObject,
            new String [] {
                "Attribute"
            }
        ) {
            boolean[] canEdit = new boolean [] {
                false
            };

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        /* Execute thread */
        processThread=new Thread(new Runnable() {
            public void run() {
            disableControls();
            reset();
            }
        });
        titleThread=new Thread(new Runnable() {
            public void run() {
                while(processThread.isAlive())setProcessingTitle(titleThread);
                enableControls();
                System.out.println("viewProfileMemberThread stopped runing.");
            }
        });
        processThread.start();
        titleThread.start();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jScrollPane1 = new javax.swing.JScrollPane();
        jTable1 = new javax.swing.JTable();
        jPanel2 = new javax.swing.JPanel();
        jPanel3 = new javax.swing.JPanel();
        picLabel = new javax.swing.JLabel();
        jComboBox1 = new javax.swing.JComboBox();
        jLabel1 = new javax.swing.JLabel();
        jPrimaryMemberNameTextField = new javax.swing.JTextField();
        jLabel3 = new javax.swing.JLabel();
        jScrollPane2 = new javax.swing.JScrollPane();
        jCommentTextArea = new javax.swing.JTextArea();
        jLabel4 = new javax.swing.JLabel();
        jPreviewButton = new javax.swing.JButton();
        jRefreshButton = new javax.swing.JButton();
        jCancelButton = new javax.swing.JButton();

        setClosable(true);
        setIconifiable(true);
        setMaximizable(true);
        setResizable(true);
        org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(openmoneyspinnersuite.OpenMS_Finance_App.class).getContext().getResourceMap(ViewProfileMembers.class);
        setTitle(resourceMap.getString("Form.title")); // NOI18N
        setToolTipText(resourceMap.getString("Form.toolTipText")); // NOI18N
        setFrameIcon(resourceMap.getIcon("Form.frameIcon")); // NOI18N
        setName("Form"); // NOI18N
        setVisible(true);

        jScrollPane1.setHorizontalScrollBarPolicy(javax.swing.ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS);
        jScrollPane1.setVerticalScrollBarPolicy(javax.swing.ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
        jScrollPane1.setName("jScrollPane1"); // NOI18N

        jTable1.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null}
            },
            new String [] {
                "Student ID", "First Name", "Middle Name", "Last Name", "Address", "City", "State", "Country", "Zip", "Sex", "Date Of Birth", "Phone", "Postal", "E-mail", "Status", "Preferred Centre Code", "Last Batch Code", "Date Recorded"
            }
        ) {
            boolean[] canEdit = new boolean [] {
                false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false
            };

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        jTable1.setName("jTable1"); // NOI18N
        jTable1.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jTable1MouseClicked(evt);
            }
        });
        jTable1.addPropertyChangeListener(new java.beans.PropertyChangeListener() {
            public void propertyChange(java.beans.PropertyChangeEvent evt) {
                jTable1PropertyChange(evt);
            }
        });
        jScrollPane1.setViewportView(jTable1);
        jTable1.getColumnModel().getColumn(0).setHeaderValue(resourceMap.getString("jTable1.columnModel.title0")); // NOI18N
        jTable1.getColumnModel().getColumn(1).setHeaderValue(resourceMap.getString("jTable1.columnModel.title4")); // NOI18N
        jTable1.getColumnModel().getColumn(2).setHeaderValue(resourceMap.getString("jTable1.columnModel.title6")); // NOI18N
        jTable1.getColumnModel().getColumn(3).setHeaderValue(resourceMap.getString("jTable1.columnModel.title5")); // NOI18N
        jTable1.getColumnModel().getColumn(4).setHeaderValue(resourceMap.getString("jTable1.columnModel.title8")); // NOI18N
        jTable1.getColumnModel().getColumn(5).setHeaderValue(resourceMap.getString("jTable1.columnModel.title11")); // NOI18N
        jTable1.getColumnModel().getColumn(6).setHeaderValue(resourceMap.getString("jTable1.columnModel.title9")); // NOI18N
        jTable1.getColumnModel().getColumn(7).setHeaderValue(resourceMap.getString("jTable1.columnModel.title10")); // NOI18N
        jTable1.getColumnModel().getColumn(8).setHeaderValue(resourceMap.getString("jTable1.columnModel.title16")); // NOI18N
        jTable1.getColumnModel().getColumn(9).setHeaderValue(resourceMap.getString("jTable1.columnModel.title14")); // NOI18N
        jTable1.getColumnModel().getColumn(10).setHeaderValue(resourceMap.getString("jTable1.columnModel.title12")); // NOI18N
        jTable1.getColumnModel().getColumn(11).setHeaderValue(resourceMap.getString("jTable1.columnModel.title15")); // NOI18N
        jTable1.getColumnModel().getColumn(12).setHeaderValue(resourceMap.getString("jTable1.columnModel.title12")); // NOI18N
        jTable1.getColumnModel().getColumn(13).setHeaderValue(resourceMap.getString("jTable1.columnModel.title13")); // NOI18N
        jTable1.getColumnModel().getColumn(14).setHeaderValue(resourceMap.getString("jTable1.columnModel.title14")); // NOI18N
        jTable1.getColumnModel().getColumn(15).setHeaderValue(resourceMap.getString("jTable1.columnModel.title15")); // NOI18N
        jTable1.getColumnModel().getColumn(16).setHeaderValue(resourceMap.getString("jTable1.columnModel.title16")); // NOI18N
        jTable1.getColumnModel().getColumn(17).setHeaderValue(resourceMap.getString("jTable1.columnModel.title17")); // NOI18N

        jPanel2.setName("jPanel2"); // NOI18N

        jPanel3.setBackground(resourceMap.getColor("jPanel3.background")); // NOI18N
        jPanel3.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.LOWERED));
        jPanel3.setName("jPanel3"); // NOI18N
        jPanel3.setPreferredSize(new java.awt.Dimension(140, 160));

        picLabel.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        picLabel.setIcon(resourceMap.getIcon("picLabel.icon")); // NOI18N
        picLabel.setName("picLabel"); // NOI18N

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(picLabel, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(picLabel, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );

        jComboBox1.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "-- Select --", "Item 2", "Item 3", "Item 4" }));
        jComboBox1.setName("jComboBox1"); // NOI18N
        jComboBox1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jComboBox1ActionPerformed(evt);
            }
        });

        jLabel1.setText(resourceMap.getString("jLabel1.text")); // NOI18N
        jLabel1.setName("jLabel1"); // NOI18N

        jPrimaryMemberNameTextField.setEnabled(false);
        jPrimaryMemberNameTextField.setName("jPrimaryMemberNameTextField"); // NOI18N

        jLabel3.setText(resourceMap.getString("jLabel3.text")); // NOI18N
        jLabel3.setName("jLabel3"); // NOI18N

        jScrollPane2.setName("jScrollPane2"); // NOI18N

        jCommentTextArea.setColumns(20);
        jCommentTextArea.setRows(5);
        jCommentTextArea.setEnabled(false);
        jCommentTextArea.setName("jCommentTextArea"); // NOI18N
        jScrollPane2.setViewportView(jCommentTextArea);

        jLabel4.setText(resourceMap.getString("jLabel4.text")); // NOI18N
        jLabel4.setName("jLabel4"); // NOI18N

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel2Layout.createSequentialGroup()
                        .addComponent(jLabel1)
                        .addGap(87, 87, 87)
                        .addComponent(jComboBox1, javax.swing.GroupLayout.PREFERRED_SIZE, 304, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel2Layout.createSequentialGroup()
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel3)
                            .addComponent(jLabel4))
                        .addGap(40, 40, 40)
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 304, Short.MAX_VALUE)
                            .addComponent(jPrimaryMemberNameTextField, javax.swing.GroupLayout.DEFAULT_SIZE, 304, Short.MAX_VALUE))))
                .addGap(134, 134, 134)
                .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, 400, javax.swing.GroupLayout.PREFERRED_SIZE))
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addContainerGap()
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel1)
                            .addComponent(jComboBox1, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel3)
                            .addComponent(jPrimaryMemberNameTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel4)))
                    .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, 160, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap())
        );

        jPreviewButton.setText(resourceMap.getString("jPreviewButton.text")); // NOI18N
        jPreviewButton.setName("jPreviewButton"); // NOI18N
        jPreviewButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jPreviewButtonActionPerformed(evt);
            }
        });

        jRefreshButton.setFont(resourceMap.getFont("jRefreshButton.font")); // NOI18N
        jRefreshButton.setIcon(resourceMap.getIcon("jRefreshButton.icon")); // NOI18N
        jRefreshButton.setText(resourceMap.getString("jRefreshButton.text")); // NOI18N
        jRefreshButton.setName("jRefreshButton"); // NOI18N
        jRefreshButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jRefreshButtonActionPerformed(evt);
            }
        });

        jCancelButton.setFont(resourceMap.getFont("jCancelButton.font")); // NOI18N
        jCancelButton.setIcon(resourceMap.getIcon("jCancelButton.icon")); // NOI18N
        jCancelButton.setText(resourceMap.getString("jCancelButton.text")); // NOI18N
        jCancelButton.setName("jCancelButton"); // NOI18N
        jCancelButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jCancelButtonActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap(629, Short.MAX_VALUE)
                .addComponent(jPreviewButton, javax.swing.GroupLayout.PREFERRED_SIZE, 109, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jRefreshButton, javax.swing.GroupLayout.PREFERRED_SIZE, 109, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jCancelButton, javax.swing.GroupLayout.PREFERRED_SIZE, 105, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(31, 31, 31))
            .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 999, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 243, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jCancelButton, javax.swing.GroupLayout.PREFERRED_SIZE, 39, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jRefreshButton, javax.swing.GroupLayout.PREFERRED_SIZE, 37, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jPreviewButton, javax.swing.GroupLayout.PREFERRED_SIZE, 37, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jCancelButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jCancelButtonActionPerformed
        if(processThread.isAlive())
        {
            try{
                processThread.stop();
                titleThread.stop();
                System.out.println("Threads successfully stopped.");
            }catch(Exception e){System.out.println("Thread stopping error: "+e);}
            this.setTitle("::. View Profile Member");
            enableControls();
        }
        else
        dispose();
    }//GEN-LAST:event_jCancelButtonActionPerformed

    private void jRefreshButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jRefreshButtonActionPerformed

        /* Execute thread */
        processThread=new Thread(new Runnable() {
            public void run() {
            disableControls();
            refreshTable("");
            resetField();
            }
        });
        titleThread=new Thread(new Runnable() {
            public void run() {
                while(processThread.isAlive())setProcessingTitle(titleThread);
                enableControls();
                System.out.println("viewProfileMemberThread stopped runing.");
            }
        });
        processThread.start();
        titleThread.start();
    }//GEN-LAST:event_jRefreshButtonActionPerformed

    public void print()
    {
        try
        {
            jTable1.print();
        }
        catch(Exception e)
        {
            e.printStackTrace();
        }
    }
    private void jTable1PropertyChange(java.beans.PropertyChangeEvent evt) {//GEN-FIRST:event_jTable1PropertyChange
        // TODO add your handling code here:
        int row;
        String memberID;
        System.out.println("Table Property Change"+jTable1.getSelectedRow());
        if(jTable1.getSelectedRow()!=-1)
        {
            row=jTable1.getSelectedRow();
            System.out.println("Table Row Selected"+row);
            memberID=jTable1.getValueAt(row,0).toString();

            picLabel.setIcon(getImage(memberID));
            if(systems.getValue(OpenMSApp.Database_A, "Select * from vwProfile where vName='"+jComboBox1.getSelectedItem().toString().trim()+"'", "cMultiRow").equalsIgnoreCase("1"))
            jPrimaryMemberNameTextField.setText(systems.getValue(OpenMSApp.Database_A,"Select * from vwMerchant where cMerchantID='"+memberID+"'",2));
            else
            jPrimaryMemberNameTextField.setText("N/A");
        }
    }//GEN-LAST:event_jTable1PropertyChange
    Icon getImage(String imagePath)
    {
        org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(openmoneyspinnersuite.OpenMSApp.class).getContext().getResourceMap(ViewProfileMembers.class);
        Icon displayedImage=resourceMap.getIcon("picLabel.icon");
        Icon stuImage=new ImageIcon(Configuration.profileImageDirPath+imagePath+".jpg");
        //getTreeLock().notify();
        if(stuImage.getIconHeight()!=-1)
        {
            displayedImage=stuImage;
        }
        return displayedImage;
    }
    private void jTable1MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jTable1MouseClicked
        profileCodeSelected();
    }//GEN-LAST:event_jTable1MouseClicked
    void profileCodeSelected()
    {
        int row;
        String memberID;
        System.out.println("Table Property Change"+jTable1.getSelectedRow());
        if(jTable1.getSelectedRow()!=-1)
        {
            row=jTable1.getSelectedRow();
            System.out.println("Table Row Selected"+row);
            memberID=jTable1.getValueAt(row,0).toString();

            picLabel.setIcon(getImage(memberID));
            //retrieving reference table details
            String profileDet[]=systems.getValue(OpenMSApp.Database_A, "Select cMultiRow,tComment,cReferenceTableCode from vwProfile where vName='"+jComboBox1.getSelectedItem().toString().trim()+"'", 1,2,3);
        if(profileDet[0].equalsIgnoreCase("1"))
        jPrimaryMemberNameTextField.setText(systems.getValue(OpenMSApp.Database_A,"Select * from vwMerchant where cMerchantID='"+memberID+"'",2));
        else
        jPrimaryMemberNameTextField.setText("N/A");
        if(profileDet[1].equalsIgnoreCase("1"))
        jCommentTextArea.setText(systems.getValue(OpenMSApp.Database_A,"Select tComment from profileMemberComment where cProfileMemberCode='"+memberID+"' and cTableCode='"+profileDet[2]+"'",1));
        }
    }
    void resetProfileCode()
    {
        String[] orderCode=systems.getTableDataArray(OpenMSApp.Database_A," vwProfile",2);
        orderCode[0]="-- Select --";
        jComboBox1.setModel(new DefaultComboBoxModel(orderCode));
    }
    void reset()
    {
        resetProfileCode();
        resetTable();
        resetField();
    }
    void resetCombo()
    {
        resetProfileCode();    
    }
private void jComboBox1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jComboBox1ActionPerformed
        String profileCode=jComboBox1.getSelectedItem().toString();
        if(profileCode.equalsIgnoreCase("-- Select --"))
        {
            resetProfileCode();
            resetTable();
        }
        else{
        /* Execute thread */
        processThread=new Thread(new Runnable() {
            public void run() {
                disableControls();
                refreshTable("");
            }
        });
        titleThread=new Thread(new Runnable() {
            public void run() {
                while(processThread.isAlive())setProcessingTitle(titleThread);
                enableControls();
                System.out.println("newProfileMember stopped runing.");
            }
        });
        processThread.start();
        titleThread.start();
        }
}//GEN-LAST:event_jComboBox1ActionPerformed

private void jPreviewButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jPreviewButtonActionPerformed
    if(jComboBox1.getSelectedItem().toString().equalsIgnoreCase("-- Select --"))
    {
        JOptionPane.showMessageDialog(JOptionPane.getRootFrame(),"PLEASE SELECT A PROFILE NAME !","ERROR !",JOptionPane.ERROR_MESSAGE);
        return;
    }
        processThread=new Thread(new Runnable() {
            public void run() {
                disableControls();
                try
                {
                    NoteWriterProfile note=new NoteWriterProfile();
                    note.writeProfile("Profile Member",query,tbAttribute,dbMemberRecord,multiRow,profileCode);
                         
                    if(OpenMSApp.d==null)
                    {
                        OpenMSApp.d=new NoteViewer("Preview Member Profile - ",Configuration.profileNotePath);
                        OpenMSApp.d.setVisible(true);
                    }
                    else if(OpenMSApp.d.isVisible()==false)
                    {
                        OpenMSApp.d=new NoteViewer("Preview Member Profile - ",Configuration.profileNotePath);
                        OpenMSApp.d.setVisible(true);       
                    }
                    else{
                        OpenMSApp.d.setTitle("Preview Member Profile ");
                        OpenMSApp.d.doTas(OpenMSApp.d.PROFILE_TABINDEX);
                        OpenMSApp.d.transferFocus();                
                    }
                }
                catch(Exception e)
                {
                    System.out.println("Error occur at ViewProfileMember.jPreviewButtonActionPerformed ! "+e);
                }
            }
        });
        titleThread=new Thread(new Runnable() {
            public void run(){
                while(processThread.isAlive())setProcessingTitle(titleThread);
                enableControls();
                System.out.println("viewProfileMemberThread stopped runing.");
            }
        });
        processThread.start();
        titleThread.start();
}//GEN-LAST:event_jPreviewButtonActionPerformed
    
    void resetTable()
    {
        tableObject=new Object[][]{};
        jTable1.setModel(new javax.swing.table.DefaultTableModel(
            tableObject,
            new String [] {
                "Attribute"
            }
        ) {
            boolean[] canEdit = new boolean [] {
                false
            };

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
    }
    private void disableControls()
    {
        jRefreshButton.setEnabled(false);
        jPreviewButton.setEnabled(false);
        jComboBox1.setEnabled(false);
    }                                             
    private void enableControls()
    {
        jRefreshButton.setEnabled(true);
        jPreviewButton.setEnabled(true);
        jComboBox1.setEnabled(true);
        this.setTitle("::. View Profile Member");
    }
                   
    private void setProcessingTitle(Thread thread)
    {
        try{
            this.setTitle("::. View Profile Member - Processing Request");
            thread.sleep(500);
            this.setTitle("::. View Profile Member - Processing Request.");
            thread.sleep(500);
            this.setTitle("::. View Profile Member - Processing Request..");
            thread.sleep(500);
            this.setTitle("::. View Profile Member - Processing Request...");
            thread.sleep(500);
        }catch(Exception e){System.out.println("Title thread"+e);}
    }
    void resetField()
    {
            picLabel.setIcon(getImage(""));
            jPrimaryMemberNameTextField.setText("");
    }
    void refreshTable(String searchPara)
    {        
        String profileName=jComboBox1.getSelectedItem().toString();
        if(profileName.equalsIgnoreCase("-- Select --"))
        {
            JOptionPane.showMessageDialog(JOptionPane.getRootFrame(),"PLEASE SELECT A PROFILE NAME !","ERROR !",JOptionPane.ERROR_MESSAGE);
            return;
        }
        profileCode=systems.getValue(OpenMSApp.Database_A, "Select cReferenceTableCode from referenceTable where vName='"+jComboBox1.getSelectedItem().toString()+"'", 1);
        multiRow=systems.getValue(OpenMSApp.Database_A, "Select cMultiRow from referenceTable where vName='"+jComboBox1.getSelectedItem().toString()+"'", "cMultirow");
        //retrieve table attribute (columns)
        tbAttribute=systems.getColumn(OpenMSApp.Database_A, "Select * from profile where cProfileCode='"+profileCode+"' order by cProfileCode,iSerial", 2);
        //invert attribute and add THREE more column for profile member code
        String[] tbAttributeInvert=new String[tbAttribute.length+3];
        /*for(int uu=3,k=tbAttribute.length;uu<tbAttribute.length+3;uu++) THIS IS THE CODE TO INVERT COLUMNS//DEPRECATED
            tbAttributeInvert[uu]=tbAttribute[--k];**/
        for(int uu=3,k=0;uu<tbAttribute.length+3;uu++)
            tbAttributeInvert[uu]=tbAttribute[k++];
        tbAttributeInvert[0]="Code";
        tbAttributeInvert[1]="Recorded By";
        tbAttributeInvert[2]="Time of Record";
        tbAttribute=tbAttributeInvert;
        //number of columns available in table
        numOfColumn=tbAttribute.length;
        //use a to determine the number of rows in a table
        String[] a=systems.getTableDataArrayNum(OpenMSApp.Database_A,jComboBox1.getSelectedItem().toString().trim().replace(' ', '_') ,1);
        int numOfRow=a.length;
        //initialize a to hold table records
        dbMemberRecord=new String[tbAttribute.length][numOfRow];
        //using for loop to retrieve table records
        for(int x=0;x<tbAttribute.length;x++)
        dbMemberRecord[x]=systems.getTableDataArrayNum(OpenMSApp.Database_A,jComboBox1.getSelectedItem().toString().trim().replace(' ', '_') ,x+1);

        
        if(searchPara.isEmpty()==false)
        {
        tbAttributeInvert[0]="c"+profileName.replace(' ', '_')+"Code";
        tbAttributeInvert[1]="cLoginCode";
        tbAttributeInvert[2]="dEntryTime";
        
            String multipleSearch[]=searchPara.split(",");
            String queryPara=" where "+systems.generateQueryPara(multipleSearch[0], tbAttribute);

            for(int k=1;k<multipleSearch.length;k++)
            {
                queryPara+=" or "+systems.generateQueryPara(multipleSearch[k], tbAttribute);
            }

            a=systems.getColumn(OpenMSApp.Database_A, "Select * from "+jComboBox1.getSelectedItem().toString().trim().replace(' ', '_') +queryPara, 1);
            numOfRow=a.length;
            //retrieve table column values
            for(int x=0;x<numOfColumn;x++)
            dbMemberRecord[x]=systems.getColumn(OpenMSApp.Database_A, "Select * from "+jComboBox1.getSelectedItem().toString().trim().replace(' ', '_') +queryPara, x+1);
        
        tbAttributeInvert[0]="Code";
        tbAttributeInvert[1]="Recorded By";
        tbAttributeInvert[2]="Time of Record";
        }
        int x=0;
        tableObject=new Object[numOfRow][numOfColumn];    
        while(x<numOfRow)
        {
            for(int xu=0;xu<numOfColumn;xu++){
                tableObject[x][xu]=dbMemberRecord[xu][x];
            }
            systems.freeHeap();
            x+=1;
            if(x==numOfRow){break;}
       }

        jTable1.setModel(new javax.swing.table.DefaultTableModel(
            tableObject,tbAttribute
        ) {
            boolean[] canEdit = systems.generateBooleanArrayFalse(numOfColumn);

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        resetField();
        jTable1.getColumnModel().getColumn(0).setMaxWidth(140);
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jCancelButton;
    private javax.swing.JComboBox jComboBox1;
    private javax.swing.JTextArea jCommentTextArea;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JButton jPreviewButton;
    private javax.swing.JTextField jPrimaryMemberNameTextField;
    private javax.swing.JButton jRefreshButton;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JTable jTable1;
    private javax.swing.JLabel picLabel;
    // End of variables declaration//GEN-END:variables

}
